<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">

<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>/Users/chriswhite/Sockets/libmiko/src/protocol.c</title><link rel="stylesheet" type="text/css" href="../styles/main.css"><script language=JavaScript src="../javascript/main.js"></script><script language=JavaScript src="../javascript/prettify.js"></script><script language=JavaScript src="../javascript/searchdata.js"></script></head><body class="ContentPage" onLoad="NDOnLoad();prettyPrint();"><script language=JavaScript><!--
if (browserType) {document.write("<div class=" + browserType + ">");if (browserVer) {document.write("<div class=" + browserVer + ">"); }}// --></script>

<!--  Generated by Natural Docs, version 1.52 -->
<!--  http://www.naturaldocs.org  -->

<!-- saved from url=(0026)http://www.naturaldocs.org -->




<div id=Content><div class="CFile"><div class=CTopic id=MainTopic><h1 class=CTitle><a name="protocol.c"></a>protocol.c</h1><div class=CBody><!--START_ND_SUMMARY--><div class=Summary><div class=STitle>Summary</div><div class=SBorder><table border=0 cellspacing=0 cellpadding=0 class=STable><tr class="SMain"><td class=SEntry><a href="#protocol.c" >protocol.c</a></td><td class=SDescription></td></tr><tr class="SGroup"><td class=SEntry><a href="#Functions" >Functions</a></td><td class=SDescription></td></tr><tr class="SFunction SIndent1 SMarked"><td class=SEntry><a href="#miko_read_data" id=link1 onMouseOver="ShowTip(event, 'tt1', 'link1')" onMouseOut="HideTip('tt1')">miko_read_data</a></td><td class=SDescription>Reads the length of a Miko packet into 32 bit integer</td></tr><tr class="SFunction SIndent1"><td class=SEntry><a href="#process_miko_data" id=link2 onMouseOver="ShowTip(event, 'tt2', 'link2')" onMouseOut="HideTip('tt2')">process_miko_data</a></td><td class=SDescription>A function to read a miko structure from a socket, with some error handling included</td></tr><tr class="SFunction SIndent1 SMarked"><td class=SEntry><a href="#miko_read_unicode_data" id=link3 onMouseOver="ShowTip(event, 'tt3', 'link3')" onMouseOut="HideTip('tt3')">miko_read_unicode_data</a></td><td class=SDescription>This function takes a temp buffer and validates it before copying it to the destination. </td></tr><tr class="SFunction SIndent1"><td class=SEntry><a href="#miko_validate_string" id=link4 onMouseOver="ShowTip(event, 'tt4', 'link4')" onMouseOut="HideTip('tt4')">miko_validate_string</a></td><td class=SDescription>Takes a string plus a max number of characters and validates that it is well-formed unicode. </td></tr><tr class="SFunction SIndent1 SMarked"><td class=SEntry><a href="#miko_send_response" id=link5 onMouseOver="ShowTip(event, 'tt5', 'link5')" onMouseOut="HideTip('tt5')">miko_send_response</a></td><td class=SDescription>Write a server response to the socket</td></tr></table></div></div><!--END_ND_SUMMARY--></div></div></div>

<div class="CGroup"><div class=CTopic><h3 class=CTitle><a name="Functions"></a>Functions</h3></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="miko_read_data"></a>miko_read_data</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>int miko_read_data(</td><td class="PType  prettyprint " nowrap>int&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>socket_descriptor,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>void&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap>*</td><td class="PParameter  prettyprint " nowrap>data,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>uint32_t&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>length,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>int&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>timeout</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><p>Reads the length of a Miko packet into 32 bit integer</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>socket_descriptor</td><td class=CDLDescription>The file descriptor of the socket</td></tr><tr><td class=CDLEntry>data</td><td class=CDLDescription>A pointer to the data that will be read in</td></tr><tr><td class=CDLEntry>length</td><td class=CDLDescription>The size of the data.&nbsp; This is set to uint32_t since the protocol uses it for packet length</td></tr><tr><td class=CDLEntry>timeout</td><td class=CDLDescription>How long before the request times out</td></tr></table><h4 class=CHeading>Returns</h4><p>MIKO_SUCCESS on success, MIKO_TIMEOUT or MIKO_POLLERROR on failure</p></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="process_miko_data"></a>process_miko_data</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>int process_miko_data(</td><td class="PTypePrefix  prettyprint " nowrap></td><td class="PType  prettyprint " nowrap>int&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>socket_descriptor,</td></tr><tr><td></td><td class="PTypePrefix  prettyprint " nowrap>struct&nbsp;</td><td class="PType  prettyprint " nowrap>Miko&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap>*</td><td class="PParameter  prettyprint " nowrap>miko,</td></tr><tr><td></td><td class="PTypePrefix  prettyprint " nowrap></td><td class="PType  prettyprint " nowrap>int&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>timeout</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><p>A function to read a miko structure from a socket, with some error handling included</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>socket_descriptor</td><td class=CDLDescription>The file descriptor of the client socket</td></tr><tr><td class=CDLEntry>miko</td><td class=CDLDescription>A pointer to the Miko structure to populate</td></tr><tr><td class=CDLEntry>timeout</td><td class=CDLDescription>The timeout in seconds to wait</td></tr></table><h4 class=CHeading>Returns</h4><p>MIKO_SUCCESS or a MIKO_ error related to socket communication or invalid data</p></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="miko_read_unicode_data"></a>miko_read_unicode_data</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>int miko_read_unicode_data(</td><td class="PType  prettyprint " nowrap>int&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>socket_descriptor,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>UChar&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap>*</td><td class="PParameter  prettyprint " nowrap>dest,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>UChar&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap>*</td><td class="PParameter  prettyprint " nowrap>buffer,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>uint32_t&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>size,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>int&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>timeout</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><p>This function takes a temp buffer and validates it before copying it to the destination.&nbsp; It uses miko_validate_string to make sure someone isn&rsquo;t passing weird things in.&nbsp; Note that Invalid characters are potentially replaced with the unknown character symbol instead.</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>socket_descriptor</td><td class=CDLDescription>The socket file descriptor to read the unicode data in from</td></tr><tr><td class=CDLEntry>dest</td><td class=CDLDescription>The destination to copy the unicode data to on success</td></tr><tr><td class=CDLEntry>buffer</td><td class=CDLDescription>The temporary buffer to hold potentially invalid data in</td></tr><tr><td class=CDLEntry>size</td><td class=CDLDescription>The number of unicode characters which will be multiplied against sizeof(UChar)</td></tr><tr><td class=CDLEntry>timeout</td><td class=CDLDescription>The number of seconds to wait until a timeout occurs</td></tr></table><h4 class=CHeading>Returns</h4><p>The number of bytes read or a MIKO_ error indicating socket issues or unicode parsing issues</p></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="miko_validate_string"></a>miko_validate_string</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>int miko_validate_string(</td><td class="PType  prettyprint " nowrap>UChar&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap>*</td><td class="PParameter  prettyprint " nowrap>string,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>uint32_t&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>max_length</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><p>Takes a string plus a max number of characters and validates that it is well-formed unicode.&nbsp; It uses u_strToUTF8 from ICU&rsquo;s &lt;unicode/ustring.h&gt; to do a dry run and validate.</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>string</td><td class=CDLDescription>The unicode string to check the validity of</td></tr><tr><td class=CDLEntry>max_length</td><td class=CDLDescription>The number of unicode characters which will be multiplied against sizeof(UChar)</td></tr></table><h4 class=CHeading>Returns</h4><p>MIKO_SUCCESS for a valid string, MIKO_ERROR for an invalid string</p></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="miko_send_response"></a>miko_send_response</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>int miko_send_response(</td><td class="PType  prettyprint " nowrap>int&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>socket_descriptor,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>int&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>response_code,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>char&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap>*</td><td class="PParameter  prettyprint " nowrap>message</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote><p>Write a server response to the socket</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>socket_descriptor</td><td class=CDLDescription>The file descriptor of the socket</td></tr><tr><td class=CDLEntry>response_code</td><td class=CDLDescription>The response code to retrieve</td></tr><tr><td class=CDLEntry>message</td><td class=CDLDescription>A human readable message describing the response</td></tr></table><h4 class=CHeading>Returns</h4><p>MIKO_SUCCESS on success, MIKO_SEND_FAILED or MIKO_MSG_TOO_LONG on failure</p></div></div></div>

</div><!--Content-->


<div id=Footer><a href="http://www.naturaldocs.org">Generated by Natural Docs</a></div><!--Footer-->


<div id=Menu><div class=MEntry><div class=MFile id=MSelected>protocol.c</div></div><div class=MEntry><div class=MFile><a href="socket-c.html">socket.c</a></div></div><div class=MEntry><div class=MGroup><a href="javascript:ToggleMenu('MGroupContent1')">Index</a><div class=MGroupContent id=MGroupContent1><div class=MEntry><div class=MIndex><a href="../index/General.html">Everything</a></div></div><div class=MEntry><div class=MIndex><a href="../index/Files.html">Files</a></div></div><div class=MEntry><div class=MIndex><a href="../index/Functions.html">Functions</a></div></div></div></div></div><script type="text/javascript"><!--
var searchPanel = new SearchPanel("searchPanel", "HTML", "../search");
--></script><div id=MSearchPanel class=MSearchPanelInactive><input type=text id=MSearchField value=Search onFocus="searchPanel.OnSearchFieldFocus(true)" onBlur="searchPanel.OnSearchFieldFocus(false)" onKeyUp="searchPanel.OnSearchFieldChange()"><select id=MSearchType onFocus="searchPanel.OnSearchTypeFocus(true)" onBlur="searchPanel.OnSearchTypeFocus(false)" onChange="searchPanel.OnSearchTypeChange()"><option  id=MSearchEverything selected value="General">Everything</option><option value="Files">Files</option><option value="Functions">Functions</option></select></div></div><!--Menu-->



<!--START_ND_TOOLTIPS-->
<div class=CToolTip id="tt1"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>int miko_read_data(</td><td class="PType  prettyprint " nowrap>int&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>socket_descriptor,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>void&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap>*</td><td class="PParameter  prettyprint " nowrap>data,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>uint32_t&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>length,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>int&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>timeout</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote>Reads the length of a Miko packet into 32 bit integer</div></div><div class=CToolTip id="tt2"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>int process_miko_data(</td><td class="PTypePrefix  prettyprint " nowrap></td><td class="PType  prettyprint " nowrap>int&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>socket_descriptor,</td></tr><tr><td></td><td class="PTypePrefix  prettyprint " nowrap>struct&nbsp;</td><td class="PType  prettyprint " nowrap>Miko&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap>*</td><td class="PParameter  prettyprint " nowrap>miko,</td></tr><tr><td></td><td class="PTypePrefix  prettyprint " nowrap></td><td class="PType  prettyprint " nowrap>int&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>timeout</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote>A function to read a miko structure from a socket, with some error handling included</div></div><div class=CToolTip id="tt3"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>int miko_read_unicode_data(</td><td class="PType  prettyprint " nowrap>int&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>socket_descriptor,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>UChar&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap>*</td><td class="PParameter  prettyprint " nowrap>dest,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>UChar&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap>*</td><td class="PParameter  prettyprint " nowrap>buffer,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>uint32_t&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>size,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>int&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>timeout</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote>This function takes a temp buffer and validates it before copying it to the destination. </div></div><div class=CToolTip id="tt4"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>int miko_validate_string(</td><td class="PType  prettyprint " nowrap>UChar&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap>*</td><td class="PParameter  prettyprint " nowrap>string,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>uint32_t&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>max_length</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote>Takes a string plus a max number of characters and validates that it is well-formed unicode. </div></div><div class=CToolTip id="tt5"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class="Prototype"><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class="PBeforeParameters  prettyprint "nowrap>int miko_send_response(</td><td class="PType  prettyprint " nowrap>int&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>socket_descriptor,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>int&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap></td><td class="PParameter  prettyprint " nowrap>response_code,</td></tr><tr><td></td><td class="PType  prettyprint " nowrap>char&nbsp;</td><td class="PParameterPrefix  prettyprint " nowrap>*</td><td class="PParameter  prettyprint " nowrap>message</td><td class="PAfterParameters  prettyprint "nowrap>)</td></tr></table></td></tr></table></blockquote>Write a server response to the socket</div></div><!--END_ND_TOOLTIPS-->




<div id=MSearchResultsWindow><iframe src="" frameborder=0 name=MSearchResults id=MSearchResults></iframe><a href="javascript:searchPanel.CloseResultsWindow()" id=MSearchResultsWindowClose>Close</a></div>


<script language=JavaScript><!--
if (browserType) {if (browserVer) {document.write("</div>"); }document.write("</div>");}// --></script></body></html>